<template>
    <div>
      <div style="background:#ECECEC; padding:30px;height: 100%">
        <a-card :bordered="false" title="修改密码" style="width: 500px;margin: auto;height:400px">
          <div style="width:300px;margin:50px auto;">
            <a-input-password v-model="password" prefix="🔒" placeholder="请输入密码" size="large"/>

            <br>
            <br>

            <a-input-password v-model="rePassword" prefix="🔒" placeholder="请确认密码" size="large"/>
            <span style="color:red" v-show="rePassword!==password">两次密码不一致</span>

            <br>
            <br>

            <a-button @click="updatePassword" type="primary" block class="input" style="height: 40px">
              修改
            </a-button>

          </div>
        </a-card>
      </div>
    </div>
</template>

<script>
  import {updatePassword} from '../api/api'
  import md5 from 'js-md5';
  import msgTip from '../msgTip'
    export default {
        name: "UpdatePass",
        data(){
            return {
                password:"",
                rePassword:"",
            }
        },
        methods:{
            /**
             * 修改密码
             */
            updatePassword(){
                if(this.password!==this.rePassword) return;
                let uid = localStorage.getItem("uid");
                if(!uid) {
                    this.$message.error("获取用户失败");
                    return;
                }

                let obj = {};
                obj.password = md5(this.password);
                obj.id = uid;
                var passArr = [];
                passArr.push(obj);

                updatePassword(JSON.stringify(passArr)).then(res=>{
                    console.log(res);
                    this.checkStatus(res.code);
                    if(res.code==200){
                        this.$message.success("修改成功");
                    }else{
                        if(res.msg){
                            this.$message.error(res.msg);
                        }else{
                            this.$message.error("修改失败");
                        }
                    }

                })
            }
        }
    }
</script>

<style scoped>

</style>
